home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / DJSRC111.ZIP / go32 / stub.c < prev    next >
C/C++ Source or Header  |  1993-08-08  |  2KB  |  79 lines

  1. /* This is file STUB.C */
  2. /*
  3. ** Copyright (C) 1993 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  4. **
  5. ** This file is distributed under the terms listed in the document
  6. ** "copying.dj", available from DJ Delorie at the address above.
  7. ** A copy of "copying.dj" should accompany this file; if not, a copy
  8. ** should be available from where this file was obtained.  This file
  9. ** may not be distributed without a verbatim copy of "copying.dj".
  10. **
  11. ** This file is distributed WITHOUT ANY WARRANTY; without even the implied
  12. ** warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. */
  14.  
  15. #include <process.h>
  16. #include <dos.h>
  17. #include <io.h>
  18. #include <string.h>
  19.  
  20. #include "gotypes.h"
  21. #include "stubinfo.h"
  22.  
  23. StubInfo stub_info = {
  24.   STUB_INFO_MAGIC,
  25.   sizeof(StubInfo),
  26.   "go32",
  27.   {
  28.     GO32_RELEASE_NUMBER,
  29.     GO32_RELEASE_TYPE_C,
  30.     GO32_MINOR_VERSION,
  31.     GO32_MAJOR_VERSION
  32.   },
  33.   262144L,
  34.   0,
  35.   "",
  36.   1,
  37.   0L
  38. };
  39.  
  40. unsigned _heaplen = 8192;
  41. unsigned _stklen = 4096;
  42.  
  43. char hex[] = "0123456789abcdef";
  44.  
  45. void x2s(int v, char *s)
  46. {
  47.   int i;
  48.   for (i=0; i<4; i++)
  49.   {
  50.     s[3-i] = hex[v&15];
  51.     v >>= 4;
  52.   }
  53.   s[4] = 0;
  54. }
  55.  
  56. char emsg[] = "Cannot exec ";
  57. char emsg2[] = "\r\n";
  58.  
  59. main(int argc, char **argv)
  60. {
  61.   char s_argc[5], s_seg[5], s_argv[5];
  62.   char s_info_seg[5], s_info_ofs[5];
  63.   int r;
  64.   x2s(argc, s_argc);
  65.   x2s(_DS, s_seg);
  66.   x2s((int)argv, s_argv);
  67.   x2s(_DS, s_info_seg);
  68.   x2s((int)(&stub_info), s_info_ofs);
  69.   /* must wait, as go32 reads argv/argc from our memory space */
  70.   r = spawnlp(P_WAIT, stub_info.go32, stub_info.go32, "!proxy", s_argc, s_seg, s_argv, s_info_seg, s_info_ofs, 0);
  71.   if (r == -1)
  72.   {
  73.     write(2, emsg, sizeof(emsg)-1);
  74.     write(2, stub_info.go32, strlen(stub_info.go32));
  75.     write(2, emsg2, sizeof(emsg2)-1);
  76.   }
  77.   return r;
  78. }
  79.